<template>
  <div style="width: 100% ">
    <div class="flex flex-a-c headerBox" @click="gotoThat">
      <div class="title">报警分析</div>
      <a-icon type="right" />
    </div>
    <div class="lightBox" style="height: 422px;">
      <!--              环形图-->
      <div class="pieChartsAlarm">
        <pieCharts
          v-if="pieData.length > 0"
          :chartData="pieData"
          :chartColor="colorList"
          :height="'180px'"
        />
      </div>
      <div class="AlarmnumBox">
        <div v-for="(item, index) in pieData" :key="index">
          <h5>{{ item.str || 0 }}</h5>
          <p>{{ item.name }}(个)</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import pieCharts from "./pieCharts.vue";

let colorList = ["#FF3535", "#FF7865", "#FFBB00", "#f8d77e"];
export default {
  name: "index",
  components: {
    pieCharts
  },
  props: {
    AlarmList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    let moment = this.$Moment;
    return {
      userName: "",
      name: "",
      role: "",
      compId: "",
      dateType: 1,
      pieData: [],
      colorList: colorList
    };
  },
  watch: {
    AlarmList(val) {
      this.AlarmListIn(val);
    }
  },
  methods: {
    gotoThat() {
      this.$store.commit("board/HeadNavType", 2);
      localStorage.setItem("navType", 2);
      this.$router.push("/statistics");
    },
    AlarmListIn(list) {
      let data = [
        { value: "0", name: "一级报警" },
        { value: "0", name: "二级报警" },
        { value: "0", name: "三级报警" },
        {
          value: "0",
          name: "四级报警"
        }
      ];
      list.forEach((item, index) => {
        if (item.alarmType == 1) {
          data[0].value = (item.rate * 100).toFixed(2);
          data[0].str = item.count;
        } else if (item.alarmType == 2) {
          data[1].value = (item.rate * 100).toFixed(2);
          data[1].str = item.count;
        } else if (item.alarmType == 3) {
          data[2].value = (item.rate * 100).toFixed(2);
          data[2].str = item.count;
        } else if (item.alarmType == 4) {
          data[3].value = (item.rate * 100).toFixed(2);
          data[3].str = item.count;
        }
      });
      this.pieData = data;
    }
  }
};
</script>

<style scoped lang="less">
.headerBox {
  margin: 20px 0 10px 0;
  .title {
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    margin: 0 4px 0 0;
  }
}
.lightBox {
  width: 100%;
  background-color: #fff;
  border-radius: 6px;
  overflow: hidden;
}
</style>
